package adapt;

public class HttpInvoker {

    public static void demo() {
        HttpInvoker.build().call(new HttpInvoker.Invoke() {

            @Override
            public void send() {
                //...
                setResult(null);
                //...
            }

            @Override
            public void oncallback(Object data) {

            }
        });
    }

    public static abstract class Invoke<T> {
        private T result;

        public HttpInvoker invoker;

        public abstract void send();

        public abstract void oncallback(T result);

        public void setInvoker(HttpInvoker invoke) {
            this.invoker = invoke;
        }

        public void setResult(T rt) {
            result = rt;
            oncallback(getResult());
        }

        public T getResult() {
            return result;
        }
    }

    public static HttpInvoker build() {
        return new HttpInvoker();
    }

    public HttpInvoker call(Invoke invoke) {
        invoke.setInvoker(this);
        invoke.send();
        return this;
    }
}

